//
//  UpdateSignatureViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/3.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "UpdateSignatureViewController.h"

#import "MineViewModel.h"

@interface UpdateSignatureViewController ()
<
    UITextViewDelegate
>
{
    
    UILabel * label;
}
@property (weak, nonatomic) IBOutlet UITextView *textView;

@property (nonatomic,strong) MineViewModel * mineViewModel;

@property (weak, nonatomic) IBOutlet UIButton *updateClick;
@end

@implementation UpdateSignatureViewController

-(MineViewModel *) mineViewModel{
    if (!_mineViewModel) {
        _mineViewModel = [[MineViewModel alloc] init];
    }
    return _mineViewModel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navigationItem setTitle:@"个性签名"];
    [self.view setBackgroundColor:DEF_COLOR_F0F0F0];
    
    
    label = [[UILabel alloc] initWithFrame:CGRectMake(3, 8, DEF_DEVICE_WIDTH - 30, 25)];
    label.enabled = NO;
    [label setText:UserInfoShare.userCenterModel.userSign];
    [label setFont:[UIFont systemFontOfSize:15.f]];
    [label setTextColor:[UIColor lightGrayColor]];
    [self.textView addSubview:label];
    
   /**
    修改签名
    */
   [[self.updateClick rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
       
       if ([MXUtility NSNULLString:self.textView.text]) {
           [MXUtility showTips:@"签名不能为空哦～"];
           return;
       }
       
       [self signNetWork];
       
   }];
    
}

-(void) signNetWork{

    [MXUtility showMBProgress:self.view message:LoadingText];
    [[self.mineViewModel updateSignRequestParameter:self.textView.text] subscribeNext:^(id x) {
        
        if ([x[@"errorcode"] integerValue] == 0) {
           
            [MXUtility showTips:@"修改签名成功~"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
        
        [MXUtility hideMBProgress:self.view];
    }error:^(NSError *error) {
        
        [MXUtility hideMBProgress:self.view];
    }];
}

-(void)textViewDidChange:(UITextView *)ttextView{
    if (ttextView.text.length == 0) {
        [label setHidden:NO];
    }else{
        [label setHidden:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
